﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using ApproveFlowEngine.EntityFrameworkCoreSplitTable.AbpCore;

using Volo.Abp.Application.Dtos;

namespace ApproveFlowEngine.Split
{
    public class SplitAppService : ApproveFlowEngineAppService, ISplitAppService
    {
        #region Private Fields

        private readonly ISplitRepository<SplitData> _repository;

        #endregion Private Fields

        #region Public Constructors

        public SplitAppService(ISplitRepository<SplitData> repository)
        {
            _repository = repository;
        }

        #endregion Public Constructors



        #region Public Methods

        public async Task Create()
        {
            var data = new SplitData() { CreateTime = DateTime.Now };
            await _repository.InsertAsync(data);
            var data2 = new SplitData() { CreateTime = DateTime.Now.AddMonths(3) };
            await _repository.InsertAsync(data2);
            var data3 = new SplitData() { CreateTime = DateTime.Now.AddMonths(4) };
            await _repository.InsertAsync(data3);
        }

        public async Task CreateList()
        {
            var data = new List<SplitData>()
            {
                new SplitData() { CreateTime = DateTime.Now.AddMonths(3) },
                new SplitData() { CreateTime = DateTime.Now.AddMonths(4) },
            };
            await _repository.InsertManyAsync(data);
        }

        public async Task GetAll()
        {
            var result = await _repository.GetListAsync(c => true);
        }

        public async Task<List<SplitData>> GetPage(PagedResultRequestDto dto)
        {
            var result = await _repository.GetPagedListAsync(c => c.CreateTime, dto.SkipCount, dto.MaxResultCount);
            return result;
        }

        #endregion Public Methods
    }
}